﻿using System;
using System.Data;
using System.Data.SqlClient;
using DBModule;

namespace DataLogical.TableClass
{
    #region tblTreatGolf
    /// <summary>
    /// This object represents the properties and methods of a tblTreatGolf.
    /// </summary>

    public class tblTreatGolf
    {
        protected int _iD;
        protected string _ourEmployee = String.Empty;
        protected int _numberOfUs;
        protected decimal _averageAmount;
        protected int _numOfPerson;
        protected decimal _totalAmount;
        protected decimal _actualFee;
        protected string _opposite = String.Empty;
        protected int _numOfOpposte;
        protected decimal _playFee;
        protected decimal _dinnerFee;

        public tblTreatGolf()
        {
        }

        public tblTreatGolf(int ID)
        {
            SqlModule db = CommonVar.s_SqlModule;
            string strSql = string.Format("SELECT ID,OurEmployee,NumberOfUs,AverageAmount,NumOfPerson,TotalAmount,ActualFee,Opposite,NumOfOpposte,PlayFee,DinnerFee FROM tblTreatGolf WHERE ID = {0}", ID);
            SqlDataReader reader = db.FastQueryBySql(strSql);
            if (reader.Read())
            {
                this.LoadFromReader(reader);
                reader.Close();
            }
            else
            {
                if (!reader.IsClosed) reader.Close();
                throw new ApplicationException("tblTreatGolf does not exist.");
            }
        }

        public tblTreatGolf(SqlDataReader reader)
        {
            this.LoadFromReader(reader);
        }

        protected void LoadFromReader(SqlDataReader reader)
        {
            if (reader != null && !reader.IsClosed)
            {
                _iD = reader.GetInt32(0);
                if (!reader.IsDBNull(1)) _ourEmployee = reader.GetString(1);
                if (!reader.IsDBNull(2)) _numberOfUs = reader.GetInt32(2);
                if (!reader.IsDBNull(3)) _averageAmount = reader.GetDecimal(3);
                if (!reader.IsDBNull(4)) _numOfPerson = reader.GetInt32(4);
                if (!reader.IsDBNull(5)) _totalAmount = reader.GetDecimal(5);
                if (!reader.IsDBNull(6)) _actualFee = reader.GetDecimal(6);
                if (!reader.IsDBNull(7)) _opposite = reader.GetString(7);
                if (!reader.IsDBNull(8)) _numOfOpposte = reader.GetInt32(8);
                if (!reader.IsDBNull(9)) _playFee = reader.GetDecimal(9);
                if (!reader.IsDBNull(10)) _dinnerFee = reader.GetDecimal(10);
            }
        }

        public void Delete(int ID)
        {
            SqlModule db = CommonVar.s_SqlModule;
            string strSql = string.Format("Delete From tblTreatGolf Where ID={0}", ID);
            db.ExecSql(strSql);
        }

        public DataTable GetAll()
        {
            string strSql = "SELECT ID,OurEmployee,NumberOfUs,AverageAmount,NumOfPerson,TotalAmount,ActualFee,Opposite,NumOfOpposte,PlayFee,DinnerFee FROM tblTreatGolf";
            SqlModule db = CommonVar.s_SqlModule;
            return db.QueryBySql(strSql);
        }

        public int Insert(tblTreatGolf obj)
        {
            int rtn = 0;
            string strSql = "Insert Into tblTreatGolf(OurEmployee,NumberOfUs,AverageAmount,NumOfPerson,TotalAmount,ActualFee,Opposite,NumOfOpposte,PlayFee,DinnerFee)Values(@OurEmployee,@NumberOfUs,@AverageAmount,@NumOfPerson,@TotalAmount,@ActualFee,@Opposite,@NumOfOpposte,@PlayFee,@DinnerFee);SELECT @@IDENTITY";
            SqlModule db = CommonVar.s_SqlModule;
            SqlModule.ParameterCollection Params = CreateParams(obj);
            DataTable dt = db.QueryBySql(strSql, Params);
            if (dt.Rows.Count == 1)
            {
                rtn = int.Parse(dt.Rows[0][0] + "");
            }
            return rtn;
        }

        public void Update(tblTreatGolf obj)
        {
            string strSql = string.Format("Update tblTreatGolf Set OurEmployee=@OurEmployee,NumberOfUs=@NumberOfUs,AverageAmount=@AverageAmount,NumOfPerson=@NumOfPerson,TotalAmount=@TotalAmount,ActualFee=@ActualFee,Opposite=@Opposite,NumOfOpposte=@NumOfOpposte,PlayFee=@PlayFee,DinnerFee=@DinnerFee Where ID={0}", obj.ID);
            SqlModule db = CommonVar.s_SqlModule;
            SqlModule.ParameterCollection Params = CreateParams(obj);
            db.ExecSql(strSql, Params);
        }

        private SqlModule.ParameterCollection CreateParams(tblTreatGolf obj)
        {
            SqlParameter Param;
            SqlModule.ParameterCollection Result = new SqlModule.ParameterCollection();

            Param = new SqlParameter("@OurEmployee", SqlDbType.VarChar);
            Result.Add(Param);
            if (obj.OurEmployee != null)
            {
                Param.Value = obj.OurEmployee;
            }
            else
            {
                Param.Value = DBNull.Value;
            }
            Param = new SqlParameter("@NumberOfUs", SqlDbType.Int);
            Result.Add(Param);
            if (obj.NumberOfUs != null)
            {
                Param.Value = obj.NumberOfUs;
            }
            else
            {
                Param.Value = DBNull.Value;
            }
            Param = new SqlParameter("@AverageAmount", SqlDbType.Decimal);
            Result.Add(Param);
            if (obj.AverageAmount != null)
            {
                Param.Value = obj.AverageAmount;
            }
            else
            {
                Param.Value = DBNull.Value;
            }
            Param = new SqlParameter("@NumOfPerson", SqlDbType.Int);
            Result.Add(Param);
            if (obj.NumOfPerson != null)
            {
                Param.Value = obj.NumOfPerson;
            }
            else
            {
                Param.Value = DBNull.Value;
            }
            Param = new SqlParameter("@TotalAmount", SqlDbType.Decimal);
            Result.Add(Param);
            if (obj.TotalAmount != null)
            {
                Param.Value = obj.TotalAmount;
            }
            else
            {
                Param.Value = DBNull.Value;
            }
            Param = new SqlParameter("@ActualFee", SqlDbType.Decimal);
            Result.Add(Param);
            if (obj.ActualFee != null)
            {
                Param.Value = obj.ActualFee;
            }
            else
            {
                Param.Value = DBNull.Value;
            }
            Param = new SqlParameter("@Opposite", SqlDbType.VarChar);
            Result.Add(Param);
            if (obj.Opposite != null)
            {
                Param.Value = obj.Opposite;
            }
            else
            {
                Param.Value = DBNull.Value;
            }
            Param = new SqlParameter("@NumOfOpposte", SqlDbType.Int);
            Result.Add(Param);
            if (obj.NumOfOpposte != null)
            {
                Param.Value = obj.NumOfOpposte;
            }
            else
            {
                Param.Value = DBNull.Value;
            }
            Param = new SqlParameter("@PlayFee", SqlDbType.Decimal);
            Result.Add(Param);
            if (obj.PlayFee != null)
            {
                Param.Value = obj.PlayFee;
            }
            else
            {
                Param.Value = DBNull.Value;
            }
            Param = new SqlParameter("@DinnerFee", SqlDbType.Decimal);
            Result.Add(Param);
            if (obj.DinnerFee != null)
            {
                Param.Value = obj.DinnerFee;
            }
            else
            {
                Param.Value = DBNull.Value;
            }
            return Result;
        }

        public static bool Exist(int ID)
        {
            SqlModule db = CommonVar.s_SqlModule;
            string strSql = string.Format("SELECT COUNT(*) From tblTreatGolf Where ID={0}", ID);
            return (db.ExecSql_Cnt(strSql) == 1);
        }

        #region Public Properties
        public int ID
        {
            get { return _iD; }
        }

        public string OurEmployee
        {
            get { return _ourEmployee; }
            set { _ourEmployee = value; }
        }

        public int NumberOfUs
        {
            get { return _numberOfUs; }
            set { _numberOfUs = value; }
        }

        public decimal AverageAmount
        {
            get { return _averageAmount; }
            set { _averageAmount = value; }
        }

        public int NumOfPerson
        {
            get { return _numOfPerson; }
            set { _numOfPerson = value; }
        }

        public decimal TotalAmount
        {
            get { return _totalAmount; }
            set { _totalAmount = value; }
        }

        public decimal ActualFee
        {
            get { return _actualFee; }
            set { _actualFee = value; }
        }

        public string Opposite
        {
            get { return _opposite; }
            set { _opposite = value; }
        }

        public int NumOfOpposte
        {
            get { return _numOfOpposte; }
            set { _numOfOpposte = value; }
        }

        public decimal PlayFee
        {
            get { return _playFee; }
            set { _playFee = value; }
        }

        public decimal DinnerFee
        {
            get { return _dinnerFee; }
            set { _dinnerFee = value; }
        }
        #endregion
    }
    #endregion
}
